<template>
  <div class="dashboard-container body-min-width">
    <h2 class="head-big-title">Invois Pembelian</h2>
    <Pathnavigation style="margin-left: 3%;"></Pathnavigation>
    <div style="width: 92%;height: 120px;margin: 20px 4% 0 4%;padding: 10px 0 0 20px;border-radius: 10px;background-color: white;">
      <el-form label-position="top" label-width="80px" :inline="true" class="head-search" :model="searchData" style="float: left;text-align: left;">
        <el-form-item label="Nombor Invois" width="188">
          <el-input v-model="searchData.invoiceId" @blur="getResetLoadData" class="input-width" placeholder="Nombor Invois" type="number"></el-input>
        </el-form-item>
        <el-form-item label="Nombor Pesanan" width="188">
          <el-input v-model="searchData.oid" @blur="getResetLoadData" class="input-width" placeholder="Nombor Pesanan" type="number"></el-input>
        </el-form-item>
        <el-form-item label="Tarikh" width="188">
          <el-date-picker
            class="input-width"
            @input="changeNew($event)"
            @change="getResetLoadData"
            v-model="searchData.date"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="Tarikh">
          </el-date-picker>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      v-loading="loading"
      :data="tableData"
      style="width: 92%;margin: 20px 4% 0 4%;padding-left: 10px;border-radius: 20px">
      <el-table-column prop="invoiceId" label="Nombor Invois"></el-table-column>
      <el-table-column prop="oid" label="Nombor Pesanan"></el-table-column>
      <el-table-column prop="date" label="Tarikh" width="135" >
        <template slot-scope="scope">
          {{$getTime(scope.row.date)}}
        </template>
      </el-table-column>
      <el-table-column prop="subFee" label="Jumlah" width="135">
        <template slot-scope="scope">
          {{$formatMoneyStr(scope.row.subFee)}}
        </template>
      </el-table-column>
      <el-table-column label="Tindakan" width="128" align="center">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            style="font-size: 26px;padding: 0;background-color: rgb(56,96,134);border: 0;"
            @click="handleEdit(scope.row)"><svg-icon icon-class="ico_view"></svg-icon></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="float: right;margin: 15px 4% 15px 0;"
      layout="prev, pager, next"
      @current-change="handleCurrentChange"
      :current-page="searchData.pageIndex"
      :page-size="searchData.pageNum"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { order_invoice_queryApi, query_masterDealerApi } from '@/api/user'

export default {
  name: 'Customers',
  computed: {
    ...mapGetters([
      'name',
      'role'
    ])
  },
  data() {
    return {
      loading: false,
      tableData: [],
      searchData: {
        pageNum: 10,
        pageIndex: 1
      },
      total: 0,
      orderChart: ''
    }
  },
  created(){
    this.$removeDetail()
    this.loadData()
  },
  mounted() {
  },
  methods: {
    getResetLoadData() {
      this.searchData.pageIndex = 1
      this.loadData()
    },
    loadData() {
      this.loading = true
      order_invoice_queryApi(this.searchData).then(res => {
        this.tableData = res.data.records
        this.total = res.data.total
        this.loading = false
      }).catch(err => {
        console.log(err)
        this.loading = false
      })
    }, // 得到数据表格
    handleEdit(row) {
      this.$router.push('/Invoices/Detail/' + row.oid)
    },
    handleCurrentChange(val) {
      this.searchData.pageIndex = val
      this.loadData()
    }
  }
}
</script>

<style lang="scss" scoped>
  .head-big-title{
    text-align: left;
    font-size: 20px;
    margin: 20px 0 0 3%;
  }
  .dashboard-container{
    margin-top: 20px;
    text-align: center;
  }

</style>
<style scoped>
  /deep/.head-search label{
    line-height: 30px;
  }
</style>
